<template>
  <!-- RegistrationUnderReview 审核中 -->
  <PageContainer>
    <view class="container">
      <Header title="审核中" />
      <view class="empty-icon">
        <image class="empty-icon" :src="img" />
        <view>报名审核中</view>
      </view>
      <TButtonGroup position="unset">
        <TButton class="gutter-btn" text="刷新审核状态" :type="'primary'" @click="__init" />
      </TButtonGroup>
      <view class="des">请联系管理员审核</view>
    </view>
  </PageContainer>
</template>

<script lang="ts" setup>
  /**  RegistrationUnderReview  审核中 */
  import PageContainer from '@/components/PageContainer/index.vue';
  import Header from '@/components/Header/index.vue';
  import { onLoad, reLaunch, switchTab } from '@/router';
  import { registrationStatus } from '@/api/activity';
  import type { IRegistrationStatusRes } from '@/api/activity/types';
  import { ref, unref } from 'vue';
  import { onPullDownRefresh } from '@dcloudio/uni-app';
  import { ApprovalStatusEnum } from '@/enums/activityStatusEnum';
  import { TabbarPageEnum } from '@/enums/pageEnum';
  import { Toast } from '@/utils';
  import TButtonGroup from '@/components/TButtonGroup/index.vue';
  import TButton from '@/components/TButtonGroup/TButton.vue';

  const img = ref('https://hb-saas.obs.cn-south-1.myhuaweicloud.com/obs/20220610/b94ac5c9e9e240bd90e710b81ff54c69.png?x-image-process=image/quality,q_50');
  const data = ref<IRegistrationStatusRes>();
  const activityId = ref<number>(0);
  const equipmentNumber = ref<string>();
  function __init() {
    return registrationStatus(activityId.value).then((r) => {
      data.value = r;
      let content = '';
      if (r.approvalStatus === ApprovalStatusEnum.REJECT || !r.approvalStatus)
        content = '审核驳回, 请重新报名';
      if (r.approvalStatus === ApprovalStatusEnum.PASSED) content = '审核已通过, 去签到';
      if (r.approvalStatus === ApprovalStatusEnum.NOTPASS) {
        return Toast({
          title: '审核未通过',
          success: () => switchTab(TabbarPageEnum.BASE_HOME),
        });
      }

      if (content) {
        uni.showModal({
          title: '提示',
          content,
          showCancel: false,
          success: () =>
            reLaunch({
              name: 'signInPage',
              options: {
                scene: activityId.value,
                equipmentNumber: unref(equipmentNumber) as string,
              },
            }),
        });
      }
      uni.stopPullDownRefresh();
    });
  }
  onLoad<'RegistrationUnderReview'>((op) => {
    activityId.value = op.activityId;
    equipmentNumber.value = op.equipmentNumber;
    __init();
  });

  onPullDownRefresh(() => __init());
</script>

<style lang="scss" scoped>
  .container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 23rpx;
    color: #333;
    padding-top: 300rpx;
    .empty-icon {
      margin-bottom: 160rpx;
      font-size: 31rpx;
      font-weight: bold;
      text-align: center;
      > image {
        width: 281rpx;
        height: 281rpx;
        margin-bottom: 30rpx;
      }
    }
    .des {
      margin-top: 30rpx;
    }
  }
</style>
